using System;
using System.Collections.Generic;
using System.Text;
using Ent.Web.Helper;
namespace Ent.Web.CSH
{
    public class HelpDocument
    {
        XMLHelper _xml;
        public HelpDocument(string lang, string serverMapPath)
        {
            _xml = GetHelpDataSource(lang, serverMapPath);
            if (_xml == null)
            {
                //Log message
            }
        }
        public string GetDetail(string name)
        {
            return Get(name, "Detail");
        }
        public string GetSummary(string name)
        {
            return Get(name, "Summary");
        }
        public string[] GetLinks(string name)
        {
            if (_xml != null)
            {
                string xPath = "//Application/Feature[@name='" + name + "']/Features/Feature";
                if (_xml.IfNodeExist(xPath))
                {
                    return _xml.GetAttributesOfAllNodes(xPath, "ref");
                }
            }
            return null;
        }
        public string Get(string name, string section)
        {
            if (_xml != null)
            {
                string xPath = "//Application/Feature[@name='" + name + "']/" + section;
                if (_xml.IfNodeExist(xPath))
                {
                    return _xml.GetInnerText(xPath);
                }
            }
            return section + " not available.";
        }
        XMLHelper GetHelpDataSource(string Language, string serverMapPath)
        {
            string path = "";
            if (System.IO.File.Exists(serverMapPath + @"\Data\Help\" + Language + ".xml"))
                path = serverMapPath + @"\Data\Help\" + Language + ".xml";
            else
                path = serverMapPath + @"\Data\Help\en-US.xml";
            if (System.IO.File.Exists(path))
            {
                try
                {
                    return new XMLHelper(path);
                }
                catch (Exception exc)
                {
                    //Log Message
                    return null;
                }
            }
            else
                return null;
        }
    }
}
